﻿<UserControl x:Class="ScrumFactory.Team.Contacts"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition"
             xmlns:props="clr-namespace:ScrumFactory.Team.Properties"
             
             x:Name="thisView"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    <TabControl Style="{StaticResource WindowTabControl}"                
                SF_Comp:CommandBehavior.RoutedEventName="Loaded"
                SF_Comp:CommandBehavior.TheCommandToRun="{Binding OnLoadCommand}">
        <TabControl.Items>
            <TabItem Header="{Binding PanelName}">
                <SF_Helpers:PanelLayout Title="{Binding PanelName}" Style="{StaticResource DetailPanelLayout}" ShowCurrentProjectName="False">

                    <!-- TOOLBAR -->
                    <SF_Helpers:PanelLayout.Toolbar>
                        <ToolBar>
                            <MenuItem Style="{StaticResource GoBackMenuItem}"/>
                            <MenuItem                                     
                                Header="{x:Static props:Resources.Add_new_contact}" Command="{Binding AddNewContactCommand}">
                                <MenuItem.Icon>
                                    <Image Source="/Images/ToolBar/add.png" Width="32" Height="32" Stretch="Uniform"/>
                                </MenuItem.Icon>
                            </MenuItem>
                        </ToolBar>                        
                    </SF_Helpers:PanelLayout.Toolbar>

                    <!-- CONTENT -->
                    <SF_Helpers:PanelLayout.Content>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <ListBox                        
                                x:Name="list"
                                Grid.Column="0"                
                                Width="250"
                                IsSynchronizedWithCurrentItem="True"
                                Background="Transparent"
                                BorderThickness="0"
                                SelectedItem="{Binding SelectedContact}"                        
                                ItemsSource="{Binding Contacts}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="auto"/>
                                                <ColumnDefinition Width="*"/>                                            
                                            </Grid.ColumnDefinitions>
                                            <Image Grid.Column="0" Source="/Images/Toolbar/Contact_Book.png" Width="32" Height="32" Margin="5" VerticalAlignment="Top" />
                                            <StackPanel Grid.Column="1">
                                                <TextBlock Text="{Binding FullName}" TextTrimming="CharacterEllipsis" Style="{StaticResource ItemTitleTextBlock}"/>
                                                <TextBlock>
                                                <Hyperlink                                                    
                                                    NavigateUri="{Binding EmailAccount}"
                                                    SF_Comp:CommandBehavior.RoutedEventName="RequestNavigate"
                                                    SF_Comp:CommandBehavior.TheCommandParameter="{Binding EmailAccount}"
                                                    SF_Comp:CommandBehavior.TheCommandToRun="{Binding DataContext.SendEmailCommand, ElementName=thisView}">
                                                    <TextBlock Text="{Binding EmailAccount}" FontSize="{StaticResource SmallFontSize}" TextTrimming="CharacterEllipsis"/>
                                                </Hyperlink>    
                                                </TextBlock>                                                
                                                <TextBlock Text="{Binding ContactData}" Foreground="{StaticResource SubTextBrush}" TextWrapping="Wrap"/>
                                            </StackPanel>
                                            
                                        </Grid>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>

                            <Grid Grid.Column="1" DataContext="{Binding ElementName=list, Path=SelectedItem}" Margin="10,0,0,0"
                                  IsEnabled="{Binding DataContext.CanEditSelectedContact, ElementName=thisView}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <TextBlock 
                                    Grid.Column="0" Grid.Row="0"                            
                                    Style="{StaticResource LabelTextBlock}"
                                    Text="{x:Static props:Resources.Full_name}"/>
                                <TextBox
                                    Grid.Column="1" Grid.Row="0"                        
                                    HorizontalAlignment="Stretch" MaxLength="50"
                                    Text="{Binding FullName, UpdateSourceTrigger=PropertyChanged}"/>
                                <TextBlock 
                                    Grid.Column="0" Grid.Row="1"                            
                                    Style="{StaticResource LabelTextBlock}"
                                    Text="{x:Static props:Resources.Email_address}"/>
                                <TextBox
                                    Grid.Column="1" Grid.Row="1"                        
                                    HorizontalAlignment="Stretch" MaxLength="50"
                                    Text="{Binding EmailAccount, UpdateSourceTrigger=PropertyChanged}"/>
                                <TextBlock 
                                    Grid.Column="0" Grid.Row="2"                            
                                    Style="{StaticResource LabelTextBlock}" VerticalAlignment="Top"
                                    Text="{x:Static props:Resources.Contact_data}"/>
                                <TextBox
                                    Grid.Column="1" Grid.Row="2"                        
                                    HorizontalAlignment="Stretch" MaxLength="50" Height="150" AcceptsReturn="True"
                                    Text="{Binding ContactData, UpdateSourceTrigger=PropertyChanged}"/>
                                <TextBlock 
                                    Grid.Column="1" Grid.Row="3"                            
                                    Style="{StaticResource LabelTextBlock}" VerticalAlignment="Top"
                                    Text="{Binding CreateBy, StringFormat={x:Static props:Resources.created_by_N}}"/>
                                <Grid.Style>
                                    <Style>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding ElementName=list, Path=Items.Count}" Value="0">
                                                <Setter Property="Grid.Visibility" Value="Collapsed"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Grid.Style>
                            </Grid>
                            
                        </Grid>
                    </SF_Helpers:PanelLayout.Content>
                </SF_Helpers:PanelLayout>
            </TabItem>
        </TabControl.Items>
    </TabControl>
</UserControl>
